`
https://leetcode.cn/problems/trapping-rain-water/
`

/**
 * @param {number[]} height
 * @return {number}
 */
var trap = function (height) {
  let left = 0, right = height.length - 1
  let l_max = 0, r_max = 0
  let res = 0

  while (left < right) {
    l_max = Math.max(l_max, height[left])
    r_max = Math.max(r_max, height[right])

    // res += min(l_max, r_max) - height[i]
    if (l_max > r_max) {
      res += r_max - height[right]
      right--
    } else {
      res += l_max - height[left]
      left++
    }
  }

  return res
};